﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class UserControlPanel : UserControl
    {
        public UserControlPanel()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (tboldpw.Text != StaticVariables.UserPw)
            {
                labelX4.Text = "(*)Ban nhap mat khau chua dung! Vui long nhap lai";
                tboldpw.Text = string.Empty;
                return;
            }
            if (tbnewpw.Text == string.Empty)
            {
                labelX5.Text = "(*)Password khong duoc phep trong!";
                return;
            }
            if (tbnewpw2.Text !=tbnewpw.Text)
            {
                labelX6.Text = "(*)Xac nhan password lan 2 chua dung!";
                tbnewpw2.Text = string.Empty;
                return;
            }
            UserDTO user = new UserDTO();
            user.ID = StaticVariables.UserID;
            user.Password = tbnewpw.Text;
            user.VaiTro = StaticVariables.UserRole;
            user.Quyen = StaticVariables.UserAuthorizationID;
            if (!UserBUS.UpdateUser(user))
            {
                MessageBox.Show("Luu khong thanh cong!");
            }
            else
            {
                btnSave.Enabled = false;
                labelX7.Text = "Luu thanh cong!";
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            tbnewpw.Text = string.Empty;
            tbnewpw2.Text = string.Empty;
            tboldpw.Text = string.Empty;
            btnSave.Enabled = true;
        }
    }
}

